<?php

namespace KyleWechat;

use Kyle\Http\Client;
use KyleWechat\Exception\InvalidConfigException;

class Config
{
    const BASEURL = 'https://api.weixin.qq.com/';
    const API = [
        'miniProgram' => [
            //get openid uri
            'openid' => 'sns/jscode2session',
            //小程序码
            'qrcode' => 'wxa/getwxacodeunlimit?access_token='
        ],
        //get access_token uri
        'access_token' => 'cgi-bin/token',
        'wechat' => [
            'userinfo' => 'sns/userinfo',
            'subscribe' => 'cgi-bin/user/info',
            'access_token' => 'sns/oauth2/access_token',
            'jsapi_ticket' => 'cgi-bin/ticket/getticket?access_token='
        ]
    ];
    private $appid;
    private $secret;

    /**
     *@var Client
     */
    public $httpClient;

    /**
     * @throws InvalidConfigException
     */
    public function __construct($appid, $secret)
    {
        if (!$appid || !$secret) {
            throw new InvalidConfigException('invalid appid or secret');
        }
        $this->appid = $appid;
        $this->secret = $secret;
        $this->httpClient = $this->getHttpClient();
    }

    public function getHttpClient(): Client
    {
        return Client::getInstance([
            'base_uri' => self::BASEURL,
            'verify'   => false
        ]);
    }

    public function getAppid()
    {
        return $this->appid;
    }

    public function getSecret()
    {
        return $this->secret;
    }
}